package Vocabulary;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import static java.lang.Thread.sleep;

public class Vocabulary {
    /**
     * collision    碰撞
     *
     * */
    @Test
    public  void  Vocabulary() throws Exception{




        for (int i=0;i<=225;i++){
            Document parse = Jsoup.parse(new URL("https://word.iciba.com/?action=words&class=11&course="+i), 6000);
            sleep(5000);
            Elements wordMainList = parse.getElementsByClass("word_main_list");
            for (Element element:wordMainList){
                Elements children = element.children();
                for (Element element1:children){
                    BufferedWriter bw = null;
                    bw = new BufferedWriter(new FileWriter("src//Vocabulary/Vocabulary.txt", true));
                    Elements children1 = element1.children();
                    for (Element element2:children1){
                        List<String> strings = element2.getElementsByTag("span").eachText();
                        if (strings.size()>0){
                            bw.write(strings.get(0)+"                 ");
                        }
                    }
                    bw.newLine();
                    bw.close();
                }
            }
            System.out.println(i);
        }
    }

}









